import axios from "@/util/http";

export default {
  state: {
    material_list: [],
  },
  getters: {},
  mutations: {},
  actions: {
    get_all_material(context, data) {
      const url = "/material/get/all/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          context.state.material_list = resp.data.data;
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    add_material_info(context, data) {
      const url = "/material/add/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      data.material.create_time = data.material.createTime;
      data.material.guarantee_period = data.material.guaranteePeriod;
      axios
        .post(url, data.material, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          data.error(resp);
          console.log(resp);
        });
    },
    modify_material_info(context, data) {
      const url = "/material/modify/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      data.material.create_time = data.material.createTime;
      data.material.guarantee_period = data.material.guaranteePeriod;
      axios
        .post(url, data.material, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          data.error(resp);
          console.log(resp);
        });
    },
    delete_material_info(context, data) {
      const url = "/material/delete/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          data.error(resp);
          console.log(resp);
        });
    },
  },
  modules: {},
};
